package cn.itcast.java.collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Author itcast
 * Date 2021/10/10 14:50
 * 实现基本的集合操作
 * Collection c = new ArrayList();
 * ArrayList 实现集合的类，可变数组
 * c.add("hadoop");
 * c.add("spark");
 * c.add("flink");
 */
public class CollectionDemo01 {
    public static void main(String[] args) {
        //Collection c = new ArrayList();
        Collection c = new ArrayList();
        c.add("hadoop");
        c.add(123);
        c.add(false);
        //给可变数组添加泛型
        Collection<String> arrs = new ArrayList<>();
        //ArrayList 实现集合的类，可变数组
        //1.public boolean add(E e) 添加元素.
        //ctrl+shift+ ↑ ↓ 移动当前行
        arrs.add("hadoop");
        arrs.add("spark");
        arrs.add("flink");

        Collection<String> arrs2 = new ArrayList<>();
        arrs2.add("hadoop");

        //2.public boolean remove(Object obj) 从集合中移除指定的元素.
        boolean flag = arrs.remove("hadoop");

        //3.public void clear() 清空集合对象
        arrs.clear();
        //4.public boolean contains(Object obj) 判断集合中是否包含指定的元素
        boolean contains = arrs.contains(arrs);
        //5.public boolean isEmpty() 判断集合是否为空
        boolean isEmpty = arrs.isEmpty();
        //6.public int size() 获取集合的长度, 即集合中元素的个数
        System.out.println(arrs.size());
    }
}
